﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cheenti.UserControls
{
    public partial class Post : System.Web.UI.UserControl
    {

        private ITemplate titleTemplate = null;

        [TemplateContainer(typeof(MessageContainer))]
        public ITemplate PostTitle
        {
            get 
            {
                return titleTemplate; 
            }
            set 
            {
                titleTemplate = value; 
            }
        }

        private ITemplate subTitleTemplate = null;

        [TemplateContainer(typeof(MessageContainer))]
        public ITemplate SubTitle
        {
            get
            {
                return subTitleTemplate;
            }
            set
            {
                subTitleTemplate = value;
            }
        }

        private ITemplate postText = null;

        [TemplateContainer(typeof(MessageContainer))]
        public ITemplate PostText
        {
            get
            {
                return postText;
            }
            set
            {
                postText = value;
            }
        }

        void Page_Init()
        {
            if (titleTemplate != null)
            {
                MessageContainer title = new MessageContainer(0);
                titleTemplate.InstantiateIn(title);
                this.postTitle.Controls.Add(title);
            }

            if (subTitleTemplate != null)
            {
                MessageContainer subTitle = new MessageContainer(0);
                subTitleTemplate.InstantiateIn(subTitle);
                this.postSubTitle.Controls.Add(subTitle);
            }

            if (postText != null)
            {
                MessageContainer text = new MessageContainer(0);
                PostText.InstantiateIn(text);
                this.text.Controls.Add(text);
            }
        }

        public class MessageContainer : Control, INamingContainer
        {
            private int index;
            internal MessageContainer(int index) { this.index = index; }
            public int Index { get { return index; } }
        }

       

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}